<?



class ImageShackUploader{
	var $login;
	var $watermark;
	var $watermark_file;
	var $tempfolder;
	var $sitename;
	
	function Upload($file){
	
	
	$linkimg_id=$this->sitename;
	
	
		$thang=date(m);
		$nam =date(Y);
			mkdir($this->tempfolder.$nam, 0777);
			mkdir($this->tempfolder.$nam."/".$thang, 0777);
			
			$this->sitename=$nam."/".$thang."/".$this->sitename."_";
			
		$filePath = $this->tempfolder . $this->sitename . $file['name'];
		move_uploaded_file($file['tmp_name'], $filePath);	
			
	
	
		
		

		
	//if($this->watermark){
			$this->Watermark($filePath, $this->watermark_file);
//	}
		//$link = parent::Upload($filePath);
		//unlink($filePath);
		

		
		
		$sqlx = "insert into linkimg (news_id,link)  ";
		$sqlx.= "values ('".$linkimg_id."','".$filePath."')";
		mysql_query($sqlx);
			
		
	
			
		
			
			
		return $link;
		
		
		
	}
	
	function Watermark($image_path, $watermark_path){
	
	
	$watermark_id = imagecreatetruecolor(140, 20);
	////$bg = imagecolorallocate ( $watermark_id, 255, 255, 255 );
	//imagefill ( $watermark_id, 0, 0, $bg );
			imagesavealpha($watermark_id, true);

		$trans_colour = imagecolorallocatealpha($watermark_id, 0, 0, 0, 127);
		imagefill($watermark_id, 0, 0, $trans_colour);



	$today = date("d-m-Y, g:ia"); 
	imagestring($watermark_id, 3, 3, 3, $today, mt_rand( 0, 0xFFFFFF ));
	
	
		//$watermark_id = imagecreatefrompng($watermark_path);
		
//		imagealphablending($watermark_id, false);
	//	imagesavealpha($watermark_id, true);
		
		$info_img = getimagesize($image_path);
		//$info_wtm = getimagesize($watermark_path);
		$fileType = strtolower($info_img['mime']);
		
		$image_w 		= $info_img[0];
		$image_h 		= $info_img[1];
		//$watermark_w	= $info_wtm[0];
		//$watermark_h	= $info_wtm[1];
		$watermark_w	= 140;
		$watermark_h	= 20;
			
		switch($fileType){
			case	'image/gif':	return false;									break;
			case	'image/png': 	$image_id = imagecreatefrompng($image_path);	break;
			default:				$image_id = imagecreatefromjpeg($image_path);	break;
		}
		/* Watermark in the bottom right of image*/
		
		$dest_x  = ($image_w - $watermark_w); 
		$dest_y  = ($image_h  - $watermark_h)-10;
		
		/* Watermark in the middle of image 
		$dest_x = round(( $image_height / 2 ) - ( $logo_h / 2 ));
		$dest_y = round(( $image_w / 2 ) - ( $logo_w / 2 ));
		*/
		imagecopy($image_id, $watermark_id, $dest_x, $dest_y, 0, 0, $watermark_w, $watermark_h);
		
		//override to image
		switch($fileType){
			case	'image/png': 	imagepng ($image_id, $image_path); 		break;
			default:				imagejpeg($image_id, $image_path); 		break;
		}       		 
		
		
		
		imagedestroy($image_id);
		imagedestroy($watermark_id);
		
		
		
		return true;
	}
	
}


?>